// // Copyright (c) 2009 All Right Reserved // // vl // // 2009-01-01 // Contains ... using System.Diagnostics.Contracts; using System.Globalization; using System.Text; using System.Xml.Linq; using JetBrains.Annotations; using LargoCommon.Abstract; namespace LargoCommon.Music { /// /// Instrument Change. /// public sealed class InstrumentChange : AbstractChange { #region Constructors /// /// Initializes a new instance of the class. /// [UsedImplicitly] public InstrumentChange() { } /// /// Initializes a new instance of the class. /// /// The given change. public InstrumentChange(XElement xchange) : base(xchange) { Contract.Requires(xchange != null); if (xchange == null) { return; } ////201509!!!!! this.Channel = (MidiChannel)LibSupport.ReadStringAttribute(xchange.Attribute("Channel")); this.Channel = DataEnums.ReadAttributeMidiChannel(xchange.Attribute("Channel")); var number = XmlSupport.ReadByteAttribute(xchange.Attribute("Instrument")); this.Instrument = new MusicalInstrument((MidiMelodicInstrument)number); this.ChangeType = MusicalChangeType.Instrument; } /// /// Initializes a new instance of the class. /// /// The given bar. /// The given line. public InstrumentChange(int givenBar, int givenLine) : base(givenBar, givenLine, MusicalChangeType.Instrument) { } /// /// Initializes a new instance of the class. /// /// The given bar. /// The given line. /// The given channel. /// The given instrument. public InstrumentChange(int givenBar, int givenLine, MidiChannel givenChannel, MusicalInstrument givenInstrument) : base(givenBar, givenLine, MusicalChangeType.Instrument) { this.Channel = givenChannel; this.Instrument = givenInstrument; } #endregion #region Properties - Xml /// /// Gets Xml representation. /// /// /// Property description. /// public override XElement GetXElement { get { var change = base.GetXElement; change.Add(new XAttribute("Instrument", this.Instrument)); change.Add(new XAttribute("Channel", this.Channel)); return change; } } #endregion #region Properties /// Gets or sets class of melodic part. /// Property description. public MusicalInstrument Instrument { get; set; } /// Gets or sets class of melodic part. /// Property description. public MidiChannel Channel { get; set; } /// /// Gets InstrumentString. /// /// General musical property. //// Do not make private!!! - It is used by DetailMusicalChanges.xaml. [UsedImplicitly] public string InstrumentString => this.Instrument.ToString(); /// /// Gets the channel string. /// /// Property description. [UsedImplicitly] public string ChannelString => this.Channel.ToString(); #endregion #region Public methods /// /// Clones this instance. /// /// Returns object. public override object Clone() { var tmc = new InstrumentChange(this.BarNumber, this.LineIndex) { Instrument = this.Instrument, Channel = this.Channel }; //// tmc.BlockModel = this.BlockModel; return tmc; } #endregion #region String representation /// String representation of the object. /// Returns value. public override string ToString() { var s = new StringBuilder(); s.AppendFormat(CultureInfo.CurrentCulture, base.ToString()); s.Append(", " + this.InstrumentString); return s.ToString(); } #endregion } }